package com.fanxuankai.boot.monitor.autoconfigure;

import com.dingtalk.api.DingTalkClient;
import com.fanxuankai.boot.monitor.DingTalkNotifier;
import com.fanxuankai.boot.monitor.Notifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * @author fanxuankai
 */
@ConditionalOnClass({DingTalkClient.class})
@ConditionalOnProperty(MonitorProperties.DingTalk.ACCESS_TOKEN)
public class DingTalkAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean
    public Notifier<?> notifier(MonitorProperties properties) {
        return new DingTalkNotifier(properties.getDingTalk());
    }
}
